var index=0;

$(function () {
    index=$("#index").val();
})

$("#btn_append").click(function () {
    index++;
    var content='<div id="specv_content'+index+'">'+
                '<div class="form-group row">'+
                '<label class="col-sm-1 text-left control-label col-form-label">内容名称</label>'+
                '<div class="col-sm-5">'+
                '<input type="text" onblur="specvName_validata(this)" id="specvName_'+index+'" index="'+index+'"  name="specvNames" placeholder="请输入规格名称" class="form-control">'+
                '</div>'+
                '<label class="col-sm-1 text-left control-label col-form-label">显示顺序</label>'+
                '<div class="col-sm-4">'+
                '<input type="text" onblur="specvSeq_validata(this)" id="specv_seq_'+index+'" index="'+index+'" name="seqs" placeholder="请输入显示顺序" class="form-control">'+
                '</div>'+
                '<button type="button" onclick="remove(this)" index="'+index+'" tag="f" class="btn btn-outline-primary">删除</button>'+
                '</div>'+
                '<div class="form-group row">'+
                '<label class="col-sm-1 text-left control-label col-form-label"></label>'+
                '<div class="col-sm-5">'+
                '<label id="specvName_info_'+index+'" class="col-sm-5 text-left control-label col-form-label"></label>'+
                '</div>'+
                '<label class="col-sm-1 text-left control-label col-form-label"></label>'+
                '<div class="col-sm-5">'+
                '<label id="specv_seq_info_'+index+'" class="col-sm-5 text-left control-label col-form-label"></label>'+
                '</div>'+
                '</div>'+
                '</div>';

    $("#specv_content").append(content);
})

function remove (element){
   if($(element).attr("tag")=="f"){
       var remove_index=$(element).attr("index");
       var item=$("#specv_content"+remove_index);
       item.remove();
   }else if ($(element).attr("tag")=="t"){

       var id=$(element).attr("specvId")
       var project_path = $("#form1").attr("project_path");
       
       $.get(project_path + "/spec/isUseBySpecvId?id="+id,function (result) {
           if(result){
               alert('抱歉，该数据与系统中其他数据存在关联，不能删除！');
           }else{
               $.ajax({
                   type: "get",
                   url: project_path + "/spec/specv/remove",
                   data: {id: id},
                   success: function (result) {
                       if (result) {
                           var remove_index=$(element).attr("index");
                           var item=$("#specv_content"+remove_index);
                           item.remove();
                       } else {
                           alert('删除规格内容失败！');
                       }
                   }
               });
           }
       });
   }
}